<extend name="Common/layout" />

<block name="title"><title>密码修改</title></block>

<block name='css'>

</block>

<block name="content">

    <!--content-->
    <div class="col-sm-offset-2">

        <div class="panel panel-default">
            <div class="panel-body" style="height:70px;">
                <div class="form-group">
                    <div class="col-sm-3">
                        <p style="font-size: 25px">密码修改</p>
                    </div>
                </div>
            </div>
        </div>
        <div class="panel panel-default" style="min-height: 500px">
            <div class="panel-body" style="margin: 20px;">
                <div class="form-group">
                    <!-- <div class="form-inline"> -->
                    <div class="input-group col-xs-6">
                        <strong class="input-group-addon" width="50px">输入密码:</strong>
                        <input class="form-control" type="password" value="" id="password_add" placeholder="Password" onblur="Check1()"/>
                    </div>
                    <input width=500 type="text" style= "color: red; border-style: solid; border-width:0" id="passwordWarn" readonly/>
                    <!-- </div> -->
                </div>
                <div class="form-group">
                    <!-- <div class="form-inline"> -->
                    <div class="input-group col-xs-6">
                        <strong class="input-group-addon" width="50px">确认密码:</strong>
                        <input class="form-control" type="password" value="" id="password1_add" placeholder="Password" onblur="Check1()"/>
                    </div>
                    <input width=500 type="text" style= "color: red; border-style: solid; border-width:0" id="passwordWarn1" readonly/>
                    <!-- </div> -->
                </div>
                <button class="btn btn-primary" type="submit" id="save" onclick="save()" disabled>确认</button>
            </div>
        </div>

        <div style="height: 200px">

        </div>
    </div>
</block>

<block name="js">

    <script type="text/javascript">
        function Check1(){
            var passwd1=$('#password_add').val();
            var passwd2=$('#password1_add').val();
            var userName_add=$('#userName_add').val();
            var email_add=$('#email_add').val();
            var college_name_add=$('#college_name_add').val();

            if(userName_add=="" || email_add=="" || college_name_add<=0){
                $('#password_add').attr("disabled",true);
                $('#password1_add').attr("disabled",true);
                return;
            }else{
                $('#password_add').attr("disabled",false);
                $('#password1_add').attr("disabled",false);
            }
            if (passwd1 =="" && passwd2!="") {
                $('#passwordWarn').val("密码空，请输入");
                $('#passwordWarn1').val("");
                $('#save').attr("disabled",true);
                return;
            }else if(passwd1!="" && passwd2==""){
                $('#passwordWarn').val("");
                $('#passwordWarn1').val("");
                $('#save').attr("disabled",true);
                return;
            }else if(passwd1=="" && passwd2==""){
                $('#passwordWarn').val("");
                $('#passwordWarn1').val("");
                $('#save').attr("disabled",true);
                return;
            }
            if (passwd1 != passwd2) {
                $('#passwordWarn').val("");
                $('#passwordWarn1').val("密码不一致，请重输入");
                $('#save').attr("disabled",true);
            } else{
                $('#passwordWarn').val("");
                $('#passwordWarn1').val("");
                $('#save').attr("disabled",false);
            }
        }

        function save(){
            var password = $('#password1_add').val();
            $.ajax({
               url:"{:U('Admin/save')}",
                type:'POST',
                dataType:'json',
                data:{
                    'password': password
                },success:function(json){
                    if(json == 'success'){
                        alert('修改密码成功！');
                        $('#password_add').val("");
                        $('#password1_add').val("");
                    }else{
                        alert('无法完成修改！');
                        $('#password_add').val("");
                        $('#password1_add').val("");
                    }
                }
            });
        }
    </script>

</block>